A Simple Example of Arduino Programs
code:arduino
// Woking a tactile switch as triggering on/off
///////////////////////////////////////////////////////////////////////////
int swt; // States of tactile switch
void setup()
{
pinMode(8, INPUT); // tactile switch 1, HIGH/LOW is OFF/ON
pinMode(10, OUTPUT); // blue LED
}
void loop()
{
do // Keeping the LED OFF unless switch pressed.
{
digitalWrite(10, LOW); // The LED is off.
delay(500); // Waiting for T=500ms swt = digitalRead(8); // State of tactile switch i in HIGH or LOW
}
while(swt == HIGH);
do // Keeping the LED ON unless switch pressed.
{
digitalWrite(10, HIGH); // The LED is on.
delay(500); // Waiting for T=500ms swt = digitalRead(8); // State of tactile switch i in HIGH or LOW
}
while(swt == HIGH);
}